function toggleDisplay(id1,id2) {
	// if id1 is hidden, then show it and hide id2. else do the opposite.
	if (document.getElementById(id1).style.display == 'none') {
		document.getElementById(id1).style.display = 'block'
		document.getElementById(id2).style.display = 'none'
	} else {
		document.getElementById(id1).style.display = 'none'
		document.getElementById(id2).style.display = 'block'
	}
	return false;
}

function toggleDisplayInline(id1,id2) {
	// if id1 is hidden, then show it and hide id2. else do the opposite.
	if (document.getElementById(id1).style.display == 'none') {
		document.getElementById(id1).style.display = 'inline'
		document.getElementById(id2).style.display = 'none'
	} else {
		document.getElementById(id1).style.display = 'inline'
		document.getElementById(id2).style.display = dtype
	}
	return false;
}

// For more explicit on and off switching
function turnDisplay(id, onOrOff)  {
    if (onOrOff == 'off') {
		 document.getElementById(id).style.display = 'none'
    } else if (onOrOff == 'on') {
		 document.getElementById(id).style.display = 'block'
    }
    return false;
}

// Yellow Fade Technique (tm 37 Signals)
var Color= new Array();
Color[2] = "ee";
Color[3] = "dd";
Color[4] = "cc";
Color[5] = "bb";
Color[6] = "aa";
Color[7] = "99";

function waittofade() {
	if (document.getElementById('fade')) {
    setTimeout("fadeIn(10)", 1000);
	 }
}

function fadeIn(where) {
    if (where >= 1) {
        document.getElementById('fade').style.backgroundColor = "#ffff" + Color[where];
		  if (where > 1) {
			  where -= 1;
			  setTimeout("fadeIn("+where+")", 200);
			} else {
			  where -= 1;
			  setTimeout("fadeIn("+where+")", 200);
			  document.getElementById('fade').style.backgroundColor = "transparent";
			}

    }
}

function popWindow(url,name,options){
        var ContextWindow = window.open(url,name,options);
        ContextWindow.opener = this;
        ContextWindow.focus();
}

var classElements = new Array();
function getElementsByClass(classname){
    var inc=0
    var alltags = document.all? document.all : document.getElementsByTagName("LI")

    for (i=0; i<alltags.length; i++){
        if (alltags[i].className==classname){
            classElements[inc] = alltags[i]
            inc += 1
        }
    }
    return classElements
}

function showMatureItems(){
    elements = getElementsByClass('mature')

    for (i=0; i<elements.length; i++){
        elements[i].style.display = 'list-item'
    }
    document.getElementById('matureLink').style.display = 'hidden'
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
        } else {
            begin += 2;
            var end = document.cookie.indexOf(";", begin);
            if (end == -1){
                end = dc.length;
            }
        }
    return unescape(dc.substring(begin + prefix.length, end));
}

function setCookie(name, value, expires, domain) {
      var curCookie = name + "=" + escape(value) +
              ((expires) ? "; expires=" + expires.toGMTString() : "") +
              "; path=/" +
              ((domain) ? "; domain=" + domain : "");
      document.cookie = curCookie;
}


function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" + 
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function flashTest() {
  if (!hasRightVersion) {
    turnDisplay('flashMap','off')
    turnDisplay('noFlashMap','on')
  }
}


function rewriteProgressLabel(){
   if (s.getValue() < 10){
       document.getElementById('progressPrefix').innerHTML = "0-1";
   } else {
       var stuff = (s.getValue() / 10);
       newStuff = stuff.toString().charAt(0);
       document.getElementById('progressPrefix').innerHTML = newStuff;
   }
}

function validatePeriod(chooser, selectId, elementId) {
  var period = chooser.form.elements[selectId].value;
  if (period == 'i_know_exact_date') {
    var blockTimePeriod = document.getElementById(selectId);
    blockTimePeriod.style.display = "none";

    var blockExactDate = document.getElementById(elementId);
    blockExactDate.style.display = "block";
  }
}

var addedTags = new Array();

// Used for inserting tags.
function insertTag(tag, container) {
    // return if tag has already been added.
    for (var i = 0; i < addedTags.length; i++) {
        if (addedTags[i].name == tag)
          return;
    }

    // Insert the tag into the form field
    $('tagbox').value=$F('tagbox')+tag+',';

    // Change the link from add to remove
    var e = $(container);
    e.className='selected';
    tag = tag.replace(/ /g, "-");
    $('del-'+tag).style.display="inline";

    // Add place into hash so we do not add it again.
    addedTags[addedTags.length] = {name:tag}
}

// Remove tag from the input text form field.
function removeInputTag(tag,container) {
    // Remove the tag from the form field
    var str = $F('tagbox');
    var tag =tag+",";
    var newTagList = str.replace(tag,"");
    document.getElementById('tagbox').value = newTagList;

    // Change the link from remove to add
    var e = $(container);
    e.style.display="none";
    tag = tag.replace(",","");
    tag = tag.replace(/ /g, "-");
    $('tag-'+tag).className='';

    // return if tag has already been added.
    for (var i = 0; i < addedTags.length; i++) {
        if (addedTags[i].name == tag)
           addedTags[i].name = null;
    }
}
